package top3.Marriages;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class MarriagesTop3Bean implements WritableComparable<MarriagesTop3Bean> {
    private String years;//年份
    private String province;//省份
    private float marriages;//结婚登记数
    public MarriagesTop3Bean(){

    }
    public MarriagesTop3Bean(String years,String province,float marriages){
        this.years = years;
        this.province = province;
        this.marriages = marriages;
    }

    public void set(String years,String province,float marriages){
        this.years = years;
        this.province = province;
        this.marriages = marriages;
    }

    public String getYears() {
        return years;
    }

    public void setYears(String years) {
        this.years = years;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public float getMarriages() {
        return marriages;
    }

    public void setMarriages(float marriages) {
        this.marriages = marriages;
    }

    @Override
    public String toString() {
        return "年份="+years+",省份="+province+",结婚登记数="+marriages;
    }

    @Override
    public int compareTo(MarriagesTop3Bean o) {
        int result ;

        int i = years.compareTo(o.getYears());

        if ( i > 0) {
            result =1;
        } else if (i <0 ) {
            result = -1;
        } else {
            // 确诊病例数倒序排序
            result = marriages > o.getMarriages() ? -1 : (marriages < o.getMarriages()? 1:0);
        }

        //if(i != 0 ){
        //    result = i;
        //}else {
        //   i =  marriages > o.getMarriages() ? -1 : (marriages < o.getMarriages()? 1:0);
        //   if(i ==0){
        //       result =1;
        //   }else {
        //       result = i;
        //   }
        //}

        return result;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(years);
        dataOutput.writeUTF(province);
        dataOutput.writeFloat(marriages);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.years = dataInput.readUTF();
        this.province = dataInput.readUTF();
        this.marriages = dataInput.readFloat();
    }
}
